/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : pop_club_app.js                                 
*  Description  : 동호회 가입하기 - 승인하기 팝업
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-05-08  이윤노    Created.
*  2012-05-08  이윤노    Complete.
*******************************************************************************/

jQuery(function($){
	
	//예/아니오 버튼객체
	function objClubJoinAppApp(){
		this._HTMLDom = null;
		this._init();
	}
	
	objClubJoinAppApp.prototype = {
		//초기화
		_init: function(){
			var $layer = $("div.pw_area02");
			
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		
		//에 버튼
		, getBtnSubmit: function(){
			var $layer= this._HTMLDom["$layer"];
			
			return $layer.find("p.pop_bt a:eq(0)");
		}
		//아니오 버튼
		, getBtnNonSubmit: function(){
			var $layer= this._HTMLDom["$layer"];
			
			return $layer.find("p.pop_bt a:eq(1)");
		}
		//X 버튼
		, getBtnClose: function(){
			var $layer= $("p.pop_close");
			
			return $layer;
		}
		 	
	}
	
	
	function clsComm(){
		this.clsSece = null;
		
		this._init();
		
	}
	
	clsComm.prototype = {
		
		_init: function() {
					
		}
		
		//동호회삭제 AJAX
		, clubJoinAppSubmit: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				var rnd = document.objUtil.random(0, 1);
				
				var resData = {
					"반환코드": rnd
					, "리턴메시지": null
				}
				
				switch(rnd){
					case 0:
						resData["리턴메시지"] = "정상";
						break;
					case 1:
						resData["리턴메시지"] = "오류";
						break;
				}
				

				$(thisClass).trigger("evtFinishClubJoinAppSubmit", [resData]);
			}, 500);
		}		
		
	}
		
	function clsControl()
	{
		this.objClubJoinAppApp = null;	
		this.objModalLoading = null;
		this._HTMLDom = null;
		
		document.objUtil.setWindowSize();
		
		this._init();
	}
	
	clsControl.prototype = {
		
		_init: function(){
			
			var q_type = document.objUtil.getParam("q_type");
			var q_key = document.objUtil.getParam("q_key");			
			
			$("div.pw_area02 p:eq(0) span.club_sece").html(q_key);
			
			if(opener){
				if(opener.document.objControl){
					this.openerControl = opener.document.objControl;
				}
			}
			
			this.objComm = new clsComm();
			this.objClubJoinApp = new objClubJoinAppApp();
			this._bind();
		}
		
		, _bind: function(){
			var thisClass = this;
			
			
			//동호회삭제 완료이벤트
			$(this.objComm).bind("evtFinishClubJoinAppSubmit", function(){
				var retData = arguments[1];
				
				document.objGlobal.spinEnd();
				opener.document.objControl.clubJoinAppRet(true);
				
				self.close();		
			});
			
			//예 버튼 클릭이벤트 
			this.objClubJoinApp.getBtnSubmit().click(function(event){
				event.preventDefault();
				
				thisClass.objComm.clubJoinAppSubmit();
			});
			
			//아니오 버튼 클릭이벤트
			this.objClubJoinApp.getBtnNonSubmit().click(function(event){
				event.preventDefault();
				
				opener.document.objControl.clubJoinAppRet(false);
				self.close();				
			});
			
			//X 버튼 클릭이벤트
			this.objClubJoinApp.getBtnClose().click(function(event){
				event.preventDefault();
				
				opener.document.objControl.clubJoinAppRet(false);
				self.close();				
			});
			
		}
	}
	
	document.objControl = new clsControl();

});
